
import type { Ref } from "vue"
import type { CommentItem, CommentLoadCondition } from "../models/Comment"
import { loadResourceCommentsAPI } from "../apis/CommentAPI"

// 加载更多评论
export const handelLoadMoreComments = async (comments: Ref<CommentItem[]>, commentLoadCondition: CommentLoadCondition, page: Ref<number>, loading: Ref<boolean>, noMore: Ref<boolean>) => {
    if (loading.value || noMore.value) return
    loading.value = true
    console.log(`评论加载资源（id：${commentLoadCondition.resourceId}）第 ${commentLoadCondition.pageIndex} 页的数据...`)

    const result = await loadResourceCommentsAPI(commentLoadCondition)
    if (result === null) {
        throw new Error("无法加载资源细节")
    }
    page.value = result.pageIndex

    if (result.results.length === 0) {
        noMore.value = true
    } else {
        comments.value.push(...result.results)
    }

    loading.value = false
}

export function handelSubmitComment(id: number, comment: string) {

};

export function handleLikeToBack(id: number, comment: CommentItem) {

};
